﻿function init() {
	resetText();

	// Configuration Options here
	
	// StartSession here
	startSession("place app ID here");
};

function startSession(appId) {
	BangoAgent.onStartSession(appId);
	setMessage("startSession");
};

function setPostURL(postUrl) {
	BangoAgent.setPostURL(postUrl);
};

function setIdentifyBangoUser(isSetToIdentify) {
	BangoAgent.setIdentifyBangoUser(isSetToIdentify);
};

function endSession() {
	BangoAgent.onEndSession();
	setMessage("endSession");
};

function log() {
	BangoAgent.onEvent(getTxtEventName(), getTxtEventValue(), getTxtEventDetail(), getEventParameters());
	setMessage("onEvent");
};

function error() {
	BangoAgent.onError("TestError", "This is my test error", "Method Name");
	setMessage("onError");
};

function pageView() {
	BangoAgent.onPageView(getTxtEventValue(), getTxtEventDetail(), getEventParameters());
	setMessage("onPageView");
};

function search() {
	BangoAgent.onSearch(getTxtEventValue(), getTxtEventDetail(), getEventParameters());
	setMessage("search");
};

function liveVideoStart() {
	BangoAgent.onLiveVideoStart(getTxtEventValue(), getTxtEventDetail(), getEventParameters());
	setMessage("onLiveVideoStart");
};

function liveVideoStop() {
	BangoAgent.onLiveVideoStop(getTxtEventValue(), getTxtEventDetail(), getEventParameters());
	setMessage("onLiveVideoStop");
};

function onDemandVideoStart() {
	BangoAgent.onDemandVideoStart(getTxtEventValue(), getTxtEventDetail(), getEventParameters());
	setMessage("onDemandVideoStart");
};

function onDemandVideoStop() {
	BangoAgent.onDemandVideoStop(getTxtEventValue(), getTxtEventDetail(), getEventParameters());
	setMessage("onDemandVideoStop");
};

function idle() {
	BangoAgent.onIdle(getTxtEventValue(), getTxtEventDetail(), getEventParameters());
	setMessage("onIdle");
};

function resume() {
	BangoAgent.onResume(getTxtEventValue(), getTxtEventDetail(), getEventParameters());
	setMessage("onResume");
};

function postNow() {
	BangoAgent.postEvents();
};

function viewBatch() {
	alert(BangoAgent.viewBatch());
};

function writelog(text) {
	document.getElementById("lblMessage").innerHTML += text + "<br/>";
};

function getEventParameters() {
	var eventParameters = null;

	if (getTxtParamName1().length > 0 || getTxtParamName2().length > 0) {
		eventParameters = new Array();
		if (getTxtParamName1().length > 0) {
			eventParameters.push(new BangoEventParameter(getTxtParamName1(), getTxtParamValue1()));
		}

		if (getTxtParamName2().length > 0) {
			eventParameters.push(new BangoEventParameter(getTxtParamName2(), getTxtParamValue2()));
		}
	}
	return eventParameters;
};

function resetText() {
	setTxtEventName("HTML5 Event");
	setTxtEventDetail("HTML5 Event Detail");
	setTxtEventValue("HTML5 Event Value");
	setTxtParamName1("BGO_SOURCE");
	setTxtParamValue1("HTML5 SOURCE");
	setTxtParamName2("BGO_TERM");
	setTxtParamValue2("HTML5 TERM");

};

function clearText() {
	setTxtEventName("");
	setTxtEventDetail("");
	setTxtEventValue("");
	setTxtParamName1("");
	setTxtParamValue1("");
	setTxtParamName2("");
	setTxtParamValue2("");

};

function setAction(message) {
	setMessage(message, true);
};

function setMessage(message, action) {
	if (!action) {
		alert(message + " logged \n " + Date());
	} else {
		alert(message);
	}

};

function setTime() {
	document.getElementById("lblTime").innerText = Date();
};

function getTxtEventName() {
	return document.getElementById("txtEventName").value;
};

function setTxtEventName(value) {
	document.getElementById("txtEventName").value = value;
};

function getTxtEventDetail() {
	return document.getElementById("txtEventDetail").value;
};

function setTxtEventDetail(value) {
	document.getElementById("txtEventDetail").value = value;
};

function getTxtEventValue() {
	return document.getElementById("txtEventValue").value;
};

function setTxtEventValue(value) {
	document.getElementById("txtEventValue").value = value;
};

function getTxtParamName1() {
	return document.getElementById("txtParamName1").value;
};

function setTxtParamName1(value) {
	document.getElementById("txtParamName1").value = value;
};

function getTxtParamValue1() {
	return document.getElementById("txtParamValue1").value;
};

function setTxtParamValue1(value) {
	document.getElementById("txtParamValue1").value = value;
};

function getTxtParamName2() {
	return document.getElementById("txtParamName2").value;
};

function setTxtParamName2(value) {
	document.getElementById("txtParamName2").value = value;
};

function getTxtParamValue2() {
	return document.getElementById("txtParamValue2").value;
};

function setTxtParamValue2(value) {
	document.getElementById("txtParamValue2").value = value;
};

function getLogLevelText() {
	var bangoLoggingLevel = new BangoLoggingLevel();
	var level = document.getElementById("txtLogLevel").value;
	var loggingLevel;
	switch (level) {
		case "1":
			loggingLevel = bangoLoggingLevel.ValuesCached.LEVEL_1;
			break;
		case "2":
			loggingLevel = bangoLoggingLevel.ValuesCached.LEVEL_2;
			break;
		case "3":
			loggingLevel = bangoLoggingLevel.ValuesCached.LEVEL_3;
			break;
		case "4":
			loggingLevel = bangoLoggingLevel.ValuesCached.LEVEL_4;
			break;
		case "5":
			loggingLevel = bangoLoggingLevel.ValuesCached.LEVEL_5;
			break;
		default:
			document.getElementById("taLogLevel").value = "Enter a valid logging level 1 - 5";
			loggingLevel = bangoLoggingLevel.ValuesCached.ALL;
	}
	return loggingLevel;
};

function loggingLevelTest() {
	var bangoLoggingLevel = new BangoLoggingLevel();
	var output = new Array();
	var eventParams = new Array();
	var eventSearch = new Array();
	var fakeEvent = new Array();
	eventSearch.push(BangoSessionEvents.EVENT_SEARCH());
	eventSearch.push(BangoSessionEvents.EVENT_VIDEOSTART());
	eventParams.push(BangoSessionEvents.EVENT_PAGEVIEW());
	fakeEvent.push("Fake Event");

	BangoAgent.setLoggingLevelEvents(bangoLoggingLevel.ValuesCached.LEVEL_1, eventParams);
	BangoAgent.setLoggingLevelEvents(bangoLoggingLevel.ValuesCached.LEVEL_2, eventSearch);
	BangoAgent.setLoggingLevelEvents(bangoLoggingLevel.ValuesCached.LEVEL_3, new Array());
	BangoAgent.setLoggingLevelEvents(bangoLoggingLevel.ValuesCached.LEVEL_4, new Array());
	BangoAgent.setLoggingLevelEvents(bangoLoggingLevel.ValuesCached.LEVEL_5, fakeEvent);

	var testEvents = new Array();
	testEvents.push(BangoSessionEvents.EVENT_PAGEVIEW());
	testEvents.push(BangoSessionEvents.EVENT_SEARCH());
	testEvents.push(BangoSessionEvents.EVENT_VIDEOSTART());
	testEvents.push(BangoSessionEvents.SESSION_START());
	testEvents.push(BangoSessionEvents.SESSION_IDLE_START());
	testEvents.push(BangoSessionEvents.SESSION_IDLE_END());

	var loggingLevel = getLogLevelText();
	if (loggingLevel != undefined) {
		BangoAgent.setLoggingLevel(loggingLevel);

		var level = BangoAgent.getLoggingLevel();
		output.push("LOGGING LEVEL " + level + " SET \n\n");
		for (var i in testEvents) {
			if (BangoAgent.EventNameAllowed(testEvents[i])) {
				output.push(testEvents[i] + " allowed\n");
			} else {
				output.push(testEvents[i] + " not allowed\n");
			}
		}
	}

	document.getElementById("taLogLevel").value = output;
};